package com.ayf.payment.game.api.service.impl;

import com.ayf.payment.game.api.entity.IpWhiteList;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.mapper.IpWhiteListMapper;
import com.ayf.payment.game.api.service.IpWhiteListService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class IpWhiteListServiceImpl implements IpWhiteListService {

    @Resource
    private IpWhiteListMapper ipWhiteListMapper;

    @Override
    public IpWhiteList selectOne(Integer merchantId) {
        if (merchantId == null) {
            throw new ParameterException("商户ID不能为空");
        }
        IpWhiteList ipWhiteList = new IpWhiteList();
        ipWhiteList.setMerchantId(merchantId);
        return ipWhiteListMapper.selectOne(ipWhiteList);
    }

    @Override
    public boolean update(IpWhiteList ipWhiteList) {
        if (ipWhiteList == null) {
            throw new ParameterException("IP白名单信息不能为空");
        }
        if (ipWhiteList.getId() == null) {
            throw new ParameterException("ID不能为空");
        }
        return ipWhiteListMapper.updateByPrimaryKeySelective(ipWhiteList) > 0;
    }
}
